package mygang.helper;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 07/08/2012
 */
public class JsonHelper {

    public static void prepareJsonResponse(Object obj,HttpServletResponse response) throws IOException{
        MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter();
        
        MediaType jsonMimeType = MediaType.APPLICATION_JSON;
        if (jsonConverter.canWrite(obj.getClass(), jsonMimeType)) {
            jsonConverter.write(obj, jsonMimeType, new ServletServerHttpResponse(response));
        }
    }

}